﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RouterControl.IO;

namespace RouterControl.Db.SchemaDbMigrator
{
	class Program
	{
		static void Main(string[] args)
		{
			var sdb = new DeviceSchemaDb(@"C:\RouterControlSchemaDb");
			var qdb = new DeviceDomDbConnector();

			foreach (var s in sdb.GetAll())
			{
				Console.WriteLine(s.FullName);

				// try load schema
				try
				{
					var trans = DeviceSchemaDomTransform.CreateFromSchemaFile(s);
	
					if (!qdb.HasDeviceSchema(trans.SchemaId))
						qdb.SaveDeviceSchema(trans);

					// check upload date
					qdb.OverwriteDeviceDomCreatedDate(trans.SchemaId, s.LastWriteTime);
				}
				catch (Exception e)
				{
					Console.WriteLine("ERROR: " + s.Name + ": " + e.Message);
				}
			}
		}
	}
}
